﻿using System;
using System.Data;
using System.Text;
using BrightFrame;
using AIM.Model;
using System.Collections.Generic;

namespace AIM.DAL
{
    public class ArchiveKindDAL
    {
        private DbProvider dbProvider = new DbProvider();

        public List<ArchiveKind> QueryAll()
        {
            List<ArchiveKind> archiveKindList = new List<ArchiveKind>();
            using (IDataReader dr = dbProvider.ExecuteDataReader("SELECT ArchiveKindID,KindName FROM archive_kind"))
            {
                while (dr.Read())
                {
                    archiveKindList.Add(new ArchiveKind
                    {
                        ArchiveKindID = dr["ArchiveKindID"].ToString(),
                        KindName = dr["KindName"].ToString()
                    });
                }
            }
            return archiveKindList;
        }
        /*
        public ArchiveKindDAL()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ArchiveKindId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from tbArchiveKind");
            strSql.Append(" where ArchiveKindId=@ArchiveKindId ");
            SqlParameter[] parameters = {
					new SqlParameter("@ArchiveKindId", SqlDbType.Char,10)};
            parameters[0].Value = ArchiveKindId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(AIM.Model.ArchiveKind model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into tbArchiveKind(");
            strSql.Append("ArchiveKindId,KindName)");
            strSql.Append(" values (");
            strSql.Append("@ArchiveKindId,@KindName)");
            SqlParameter[] parameters = {
					new SqlParameter("@ArchiveKindId", SqlDbType.Char,2),
					new SqlParameter("@KindName", SqlDbType.NVarChar,20)};
            parameters[0].Value = model.ArchiveKindId;
            parameters[1].Value = model.KindName;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(AIM.Model.ArchiveKind model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update tbArchiveKind set ");
            strSql.Append("KindName=@KindName");
            strSql.Append(" where ArchiveKindId=@ArchiveKindId ");
            SqlParameter[] parameters = {
					new SqlParameter("@ArchiveKindId", SqlDbType.Char,2),
					new SqlParameter("@KindName", SqlDbType.NVarChar,20)};
            parameters[0].Value = model.ArchiveKindId;
            parameters[1].Value = model.KindName;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string ArchiveKindId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tbArchiveKind ");
            strSql.Append(" where ArchiveKindId=@ArchiveKindId ");
            SqlParameter[] parameters = {
					new SqlParameter("@ArchiveKindId", SqlDbType.Char,10)};
            parameters[0].Value = ArchiveKindId;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public AIM.Model.ArchiveKind GetModel(string ArchiveKindId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ArchiveKindId,KindName from tbArchiveKind ");
            strSql.Append(" where ArchiveKindId=@ArchiveKindId ");
            SqlParameter[] parameters = {
					new SqlParameter("@ArchiveKindId", SqlDbType.Char,10)};
            parameters[0].Value = ArchiveKindId;

            AIM.Model.ArchiveKind model = new AIM.Model.ArchiveKind();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.ArchiveKindId = ds.Tables[0].Rows[0]["ArchiveKindId"].ToString();
                model.KindName = ds.Tables[0].Rows[0]["KindName"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ArchiveKindId,KindName ");
            strSql.Append(" FROM tbArchiveKind ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ArchiveKindId,KindName ");
            strSql.Append(" FROM tbArchiveKind ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "tbArchiveKind";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/
    }
}

